<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\index\controller;

use think\admin\Controller;


/**
 * Class Search
 * @package app\index\controller
 */
class Search extends BaseController
{

    //行业动态对应的分类ID
    static private $type = array(
        "work"=> array("协会工作", array(19,30)),
        "notice"=>array("培训通知", array(16)),
        "news"=>array("新闻动态", array(15))
    );

    public function index()
    {

        $this->search_type = $this->request->get("search-type");
        $this->search_keyword = $this->request->get("search-keyword");

        if(array_key_exists($this->search_type, self::$type)==false){
            exit("错误的参数");
        }

        $type_name = self::$type[$this->search_type][0];
        $this->title = $type_name."搜索";

        $selected = self::$type[$this->search_type][1];
        $pager = $this->_prepare_page_info($selected,5,$this->search_keyword);
        $this->news = array(
            "list" => $this->_get_category_articles($selected, $pager['offset'],$pager['limit'],$this->search_keyword),
            "pager" => $pager,
        );

        $this->_get_nav_menus();
        $this->_system();
        $this->fetch();


    }

    public function detail()
    {

        $id = $this->request->get("id");

        $this->_inc_read_num($id);
        $this->article = $this->_get_article($id);
        $this->title = $this->article['title'];

        $this->_get_nav_menus();
        $this->_system();
        $this->fetch("common/detail");
    }

}